---
title: "The Source of Economic Shocks Matters for Their Political Outcomes"
subtitle: "Replication file (Research & Politics, 2025)"
author: "Leonardo Baccini, Costin Ciobanu, and Krzysztof Pelc"
date: "2025-08-26"
output:
  html_document:
    toc: true
    toc_depth: 3
editor_options: 
  chunk_output_type: console
---

# Associated Paper

```{r intro-link, echo=FALSE, results='asis'}

cat("This replication package accompanies the paper [**The Source of Economic Shocks Matters for Their Political Outcomes**](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5395297), forthcoming at *Research & Politics* (2025).")

```

# R version

```{r}

# The analysis was conducted using R version 4.3.2 (2023-10-31).
sessionInfo()

```

# Load packages and relevant functions/themes

```{r}

# Load relevant packages
pacman::p_load(foreign, psych, texreg, tidyverse, dplyr, data.table, readxl, grid, gridExtra, zoo, MASS, miceadds, scales, patchwork, lfe, haven, lubridate, readtext, cobalt, estimatr, xtable, kableExtra, randomizr, sciplot, stringi, knitr, margins, sjPlot, stats, effects, diagis, ISLR, writexl, car, janitor, marginaleffects)

# Different functions
options(digits = 2, scipen = 10)
select = dplyr::select
`%nin%` <- function (x, table) is.na(match(x, table, nomatch=NA_integer_))

# Plot theme (ggplot)
theme <- theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold")) +
  theme(plot.subtitle = element_text(hjust = 0.5)) +
  theme(text = element_text(size=20)) +
  theme(strip.text.x = element_text(size = 20, face="bold")) +
  theme(strip.text.y = element_text(size = 20, face="bold")) +
  theme(axis.text.x= element_text(size = 20)) +
  theme(axis.text.y = element_text(size = 20)) +
  theme(axis.title.x= element_text(size = 26)) +
  theme(axis.title.y = element_text(size = 26))

# Create the Plots folder if necessary
if (!dir.exists("Plots")) dir.create("Plots", recursive = TRUE)

```

# Read the data

```{r}

data <- readRDS("Data_BCP2025.RDS")

```

# Create new variables

```{r warning=FALSE}

data = mutate(data,
              
              # Create new globalization and redistribution variables
              Low_globalization = ifelse(Globalization <= 2, 1, 0),
              Low_redistribution = ifelse(Redistribution <= 2, 1, 0),
              
              # Create binary outcomes
              Prevent_layoffs_binary = ifelse(Prevent_layoffs > 5, 1, 0),
              Populism_binary = ifelse(Populism > 5, 1, 0),
              Authoritarianism_binary = ifelse(Authoritarianism > 5, 1, 0),
              Listens_people_binary = ifelse(Listens_people > 5, 1, 0), 
              Outsider_binary = ifelse(Outsider > 5, 1, 0), 
              Unconstrained_rules_binary = ifelse(Unconstrained_rules > 5, 1, 0), 
              Violence_needed_binary = ifelse(Violence_needed > 5, 1, 0), 
              Local_constituents_binary = ifelse(Local_constituents > 5, 1, 0))

```

# Main paper

## Table 2 (main results)

```{r}

# 1. The main results

tab2 = list()

tab2[[1]] = lm_robust(data = data, Prevent_layoffs ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tab2[[2]] = lm_robust(data = data, Populism ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tab2[[3]] = lm_robust(data = data, Authoritarianism ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tab2, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Automation", "Offshoring"), reorder.coef = c(3, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Politicians should prevent these layoffs - model 1; Populism - model 2; Authoritarianism - model 3. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tab2[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tab2[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tab2[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")

# 3. Obtaining Bonferroni-adjusted p-values

p_values <- numeric()

## Loop through each of the 3 models stored in tab2
for (i in 1:length(tab2)) {
  ## Extract p-values for coefficients containing "Exp_cond" in the current model
  exp_cond_rows <- grep("Exp_cond", rownames(summary(tab2[[i]])$coefficients))
  p_values_i <- summary(tab2[[i]])$coefficients[exp_cond_rows, "Pr(>|t|)"]
  
  ## Append the extracted p-values to the overall vector
  p_values <- c(p_values, p_values_i)
}

## Print all extracted p-values
round(p_values, 3)

## Apply Bonferroni adjustment (accounting for 9 comparisons: 3 per model × 3 models)
adjusted_p_values <- p.adjust(p_values, method = "bonferroni", n = 9)

## Print Bonferroni-adjusted p-values
round(adjusted_p_values, 3)

```

# Online Appendix

## Appendix A

### Table A.1

```{r warning=FALSE}

# Display survey demographics (distribution of quota variables)

## Variables to obtain proportions for
vars <- c("Sex", "Age_cat", "Region", "Empl_status_binary")

## Loop through variables and create proportion tables
prop_tables <- lapply(vars, function(v) {
  data %>%
    tabyl(!!sym(v)) %>%       # frequency + proportion
    adorn_pct_formatting(digits = 1) %>%   # show % with 1 decimal
    adorn_ns()                # show counts alongside %
})

## Print tables
names(prop_tables) <- vars
prop_tables

```

## Appendix B

### Table B.1

```{r}

# Balance test function
balance_test <- function(data, vars, dependent_var) {
  # Initialize results dataframe
  results_df <- data.frame(variable = character(),
                           dep_var = character(),
                           test_used = character(),
                           p_value = numeric(),
                           stringsAsFactors = FALSE)
  
  # Determine type of dependent variable
  dep_type <- ifelse(is.numeric(data[[dependent_var]]), "numeric", "factor")
  
  for (var in vars) {
    if (dep_type == "numeric") {
      # Use ANOVA if dependent variable is numeric
      model <- aov(as.formula(paste(dependent_var, var, sep = " ~ ")), data = data)
      p_val <- summary(model)[[1]][["Pr(>F)"]][1]
      test <- "ANOVA"
    } else {
      # Use Chi-squared test if dependent variable is factor
      tbl <- table(data[[var]], data[[dependent_var]])
      test <- "Chi-squared"
      # Ensure there are no zero rows/cols that break chisq.test
      if (all(dim(tbl) > 1)) {
        p_val <- suppressWarnings(chisq.test(tbl)$p.value)
      } else {
        p_val <- NA
      }
    }
    
    results_df <- rbind(results_df, 
                        data.frame(variable = var,
                                   dep_var = dependent_var,
                                   test_used = test,
                                   p_value = p_val,
                                   stringsAsFactors = FALSE))
  }
  
  return(results_df)
}

## Call the function to perform ANOVA for multiple variables and store p-values
anova_results <- balance_test(
  data = data, 
  vars = c("White_nh", "College_grad", "Big_city", "Working_now", "Under50k", "Female", "Age_under36", "Region_South", "Democrat", "Voted_Biden", "Polint_high"), 
  dependent_var = "Exp_cond"
)

# Define a named vector for mapping
rename_map <- c(
  "Big_city" = "Big city residence",
  "Age_under36" = "Age under 36",
  "Female" = "Female",
  "College_grad" = "College graduate",
  "White_nh" = "White (Hispanics excluded)",
  "Working_now" = "Working",
  "Region_South" = "Region (South)",
  "Democrat" = "Democrat",
  "Voted_Biden" = "Voted Biden",
  "Polint_high" = "High political interest",
  "Liberal" = "Liberal",
  "Under50k" = "Annual income under 50k"
)

# Rename the variables
anova_results <- anova_results %>%
  mutate(variable = as.character(variable),
         variable = rename_map[variable],
         p_value = round(p_value, 2))

# Print results dataframe
anova_results # %>%  xtable()

```

## Appendix D

### Table D.1

```{r warning=FALSE}

# Display descriptive statistics

descriptives = c("Prevent_layoffs", "Populism", "Authoritarianism", "Listens_people", "Outsider", "Unconstrained_rules", "Violence_needed", "Local_constituents", "Offshoring_cond", "Automation_cond", "Bankruptcy_cond", "Male", "White_nh", "NonCollege_grad", "Manufacturing", "Big_city", "Age_under36", "Region_South", "Working_now", "Democrat", "Republican", "Polint_high", "Voted_Biden", "Liberal", "Low_redistribution", "Low_globalization")

data_sub <- dplyr::select(data, descriptives)

psych::describe(data_sub, skew = TRUE, check = TRUE) %>%
  as.data.frame() %>%
  dplyr::select(n, mean, sd, median, min, max, se) %>%
  round(2) # %>% xtable()

```

## Appendix E

### Table E.1

```{r}

# 1. The results

tabe1 = list()

tabe1[[1]] = lm_robust(data = data, Listens_people ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe1[[2]] = lm_robust(data = data, Outsider ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe1[[3]] = lm_robust(data = data, Unconstrained_rules ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe1[[4]] = lm_robust(data = data, Violence_needed ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe1[[5]] = lm_robust(data = data, Local_constituents ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe1, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Automation", "Offshoring"), reorder.coef = c(3, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Politician who listens to the people - model 1; Political outsider - model 2; Politician unconstrained by rules - models 3; Politician who does not rule out force - model 4; Politician who accepts divisiveness - model 5. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe1[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe1[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe1[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe1[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe1[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Table E.2

```{r}

# 1. The results

tabe2 = list()

tabe2[[1]] = lm_robust(data = data, Prevent_layoffs_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe2[[2]] = lm_robust(data = data, Populism_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe2[[3]] = lm_robust(data = data, Authoritarianism_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe2, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Automation", "Offshoring"), reorder.coef = c(3, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (binary): Politicians should prevent these layoffs - model 1; Populism - model 2; Authoritarianism - model 3. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe2[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe2[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe2[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Table E.3

```{r}

# 1. The results

tabe3 = list()

tabe3[[1]] = lm_robust(data = data, Listens_people_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe3[[2]] = lm_robust(data = data, Outsider_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe3[[3]] = lm_robust(data = data, Unconstrained_rules_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe3[[4]] = lm_robust(data = data, Violence_needed_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe3[[5]] = lm_robust(data = data, Local_constituents_binary ~ Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe3, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Automation", "Offshoring"), reorder.coef = c(3, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (binary): Politician who listens to the people - model 1; Political outsider - model 2; Politician unconstrained by rules - models 3; Politician who does not rule out force - model 4; Politician who accepts divisiveness - model 5. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe3[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe3[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe3[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe3[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe3[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Table E.4

```{r}

# 0. Data recode

data = mutate(data,
             Low_redistribution1 = factor(Low_redistribution, labels = c("Higher redistribution support", "Low redistribution support")))

# 1. The results

tabe4 = list()

tabe4[[1]] = lm_robust(data = data, Prevent_layoffs ~ Low_redistribution1*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe4, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Low redistribution support", "Automation", "Offshoring", "Automation * Low redistribution support", "Offshoring * Low redistribution support"), reorder.coef = c(4, 3, 6, 5, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variable (0 - 10): Politicians should prevent these layoffs - model 1. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-value indicates whether we can reject the null hypothesis of equality).

linearHypothesis(tabe4[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Table E.5

```{r}

# 0. Data recode

data = mutate(data,
             Low_globalization1 = factor(Low_globalization, labels = c("Higher globalization support", "Low globalization support")))

# 1. The results

tabe5 = list()

tabe5[[1]] = lm_robust(data = data, Populism ~ Low_globalization1*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe5[[2]] = lm_robust(data = data, Authoritarianism ~ Low_globalization1*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe5, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Low globalization support", "Automation", "Offshoring", "Low globalization support x Automation", "Low globalization support x Offshoring"), reorder.coef = c(4,3,2,6,5, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Populism - model 1; Authoritarianism - model 2. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe5[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe5[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Table E.6

```{r results='asis'}

# 1. The results

tabe6 = list()

tabe6[[1]] = lm_robust(data = data, Authoritarianism ~ Republican*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe6[[2]] = lm_robust(data = data, Authoritarianism ~ Voted_Trump*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe6[[3]] = lm_robust(data = data, Authoritarianism ~ Male*Exp_cond + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe6[[4]] = lm_robust(data = data, Authoritarianism ~ Rural*Exp_cond + Age + Empl_status + Education + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe6[[5]] = lm_robust(data = data, Authoritarianism ~ White_nh*Exp_cond + Age + Empl_status + Education + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe6[[6]] = lm_robust(data = data, Authoritarianism ~ NonCollege_grad*Exp_cond + Age + Empl_status + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

cat('<div style="font-size: 80%;">') # use htmlreg for knitting, otherwise use screenreg
htmlreg(tabe6, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Republican", "Automation", "Offshoring", "Republican x Automation", "Republican x Offshoring", "Voted Trump", "Voted Trump x Automation", "Voted Trump x Offshoring", "Male", "Male x Automation", "Male x Offshoring", "Rural", "Rural x Automation", "Rural x Offshoring", "White (non-Hispanic)", "White (non-Hispanic) x Automation",  "White (non-Hispanic) x Offshoring", "Non-college graduate", "Non-college graduate x Automation", "Non-college graduate x Offshoring"), reorder.coef = c(4, 3, 6, 5, 9, 8, 12, 11, 15, 14, 18, 17, 21, 20, 2, 7, 10, 13, 16, 19, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variable for all models: Authoritarianism (0-10). The bankruptcy vignette is the reference category. The models include controls. All displayed variables are binary.", caption = "Effect heterogeneity tests (authoritarianism)")
cat('</div>')

```

### Table E.6 cont.

```{r}

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe6[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe6[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe6[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe6[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe6[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe6[[6]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Figure E.1

```{r  warning=FALSE, fig.width=15, fig.height=15}

# Create function to extract interaction terms

extract_interactions_only <- function(model) {
  tidy(model, conf.int = TRUE, conf.level = 0.95) %>%
    filter(str_detect(term, ":Exp_cond")) %>%
    dplyr::rename(conf.low_95 = conf.low, conf.high_95 = conf.high) %>%
    left_join(
      tidy(model, conf.int = TRUE, conf.level = 0.90) %>%
        filter(str_detect(term, ":Exp_cond")) %>%
        dplyr::select(term, conf.low, conf.high) %>%
        dplyr::rename(conf.low_90 = conf.low, conf.high_90 = conf.high),
      by = "term"
    )
}

# Extract interaction terms from all models
interaction_terms_all <- map_dfr(tabe6, extract_interactions_only, .id = "model_id")

# Create a moderator variable to group the interaction terms
interaction_terms_all <- interaction_terms_all %>%
  mutate(
    moderator = str_extract(term, "^[^:]+") %>% str_replace("_", " "),
    term = str_replace(term, ".*:Exp_cond", "Exp_cond"),
    term_label = paste(moderator, term, sep = " x ")  # Combine for unique labeling
  )

# Reorder the moderator factor levels
interaction_terms_all$moderator <- factor(
  interaction_terms_all$moderator,
  levels = c("Male", "White nh", "NonCollege grad", "Rural", "Republican", "Voted Trump")
)

# Create a named vector for custom facet labels
facet_labels <- c(
  "Male" = "Male",
  "White nh" = "White Non-Hispanic",
  "NonCollege grad" = "Non-college graduate",
  "Rural" = "Rural",
  "Republican" = "Republican",
  "Voted Trump" = "Voted for Trump"
)

# Update the term_label to have only two labels: Automation and Offshoring
interaction_terms_all$term_label <- ifelse(
  grepl("Automation", interaction_terms_all$term_label), 
  "Automation", 
  "Offshoring"
)

# Plot the figure
ggplot(interaction_terms_all, aes(x = reorder(term_label, estimate), y = estimate)) +
  geom_point(size = 3, shape = 21, fill = "black", color = "black") +  
  geom_errorbar(aes(ymin = conf.low_90, ymax = conf.high_90), width = 0, size = 1.2) +  
  geom_errorbar(aes(ymin = conf.low_95, ymax = conf.high_95), width = 0, size = 0.8, linetype = "solid") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red", size = 1) +  
  labs(
    title = "",
    x = "",
    y = "Estimate of the interaction term\n(with 90% and 95% confidence intervals)"
  ) +
  coord_flip() +
  facet_wrap(~moderator, scales = "free_y", ncol = 1, labeller = labeller(moderator = facet_labels)) +  
  theme(
    axis.text.y = element_text(size = 10, hjust = 1),
    strip.text = element_text(size = 12, face = "bold"),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank()
  ) +
  theme

# To save the figure, please execute the below code:
#ggsave("Plots/FigE1_Heterogeneity_all.pdf", dpi = 1200, width = 15, height = 15, unit = "in")

```

### Table E.7

```{r results='asis'}

# 1. The results

tabe7 = list()

tabe7[[1]] = lm_robust(data = data, Unconstrained_rules ~ Republican*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe7[[2]] = lm_robust(data = data, Unconstrained_rules ~ Voted_Trump*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe7[[3]] = lm_robust(data = data, Unconstrained_rules ~ Male*Exp_cond + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe7[[4]] = lm_robust(data = data, Unconstrained_rules ~ Rural*Exp_cond + Age + Empl_status + Education + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe7[[5]] = lm_robust(data = data, Unconstrained_rules ~ White_nh*Exp_cond + Age + Empl_status + Education + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe7[[6]] = lm_robust(data = data, Unconstrained_rules ~ NonCollege_grad*Exp_cond + Age + Empl_status + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

cat('<div style="font-size: 80%;">') # use htmlreg for knitting, otherwise use screenreg
htmlreg(tabe7, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Republican", "Automation", "Offshoring", "Republican x Automation", "Republican x Offshoring", "Voted Trump", "Voted Trump x Automation", "Voted Trump x Offshoring", "Male", "Male x Automation", "Male x Offshoring", "Rural", "Rural x Automation", "Rural x Offshoring", "White (non-Hispanic)", "White (non-Hispanic) x Automation",  "White (non-Hispanic) x Offshoring", "Non-college graduate", "Non-college graduate x Automation", "Non-college graduate x Offshoring"), reorder.coef = c(4, 3, 6, 5, 9, 8, 12, 11, 15, 14, 18, 17, 21, 20, 2, 7, 10, 13, 16, 19, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variable for all models: Politician unconstrained by rules (0-10). The bankruptcy vignette is the reference category. The models include controls. All displayed variables are binary.", caption = "Effect heterogeneity tests (Politician unconstrained by rules)")
cat('</div>')

```

### Table E.7 cont.

```{r}

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe7[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe7[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe7[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe7[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe7[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe7[[6]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Figure E.2

```{r warning=FALSE, fig.width=15, fig.height=15}

# Create function to extract interaction terms

extract_interactions_only <- function(model) {
  tidy(model, conf.int = TRUE, conf.level = 0.95) %>%
    filter(str_detect(term, ":Exp_cond")) %>%
    dplyr::rename(conf.low_95 = conf.low, conf.high_95 = conf.high) %>%
    left_join(
      tidy(model, conf.int = TRUE, conf.level = 0.90) %>%
        filter(str_detect(term, ":Exp_cond")) %>%
        dplyr::select(term, conf.low, conf.high) %>%
        dplyr::rename(conf.low_90 = conf.low, conf.high_90 = conf.high),
      by = "term"
    )
}

# Extract interaction terms from all models
interaction_terms_all <- map_dfr(tabe7, extract_interactions_only, .id = "model_id")

# Create a moderator variable to group the interaction terms
interaction_terms_all <- interaction_terms_all %>%
  mutate(
    moderator = str_extract(term, "^[^:]+") %>% str_replace("_", " "),
    term = str_replace(term, ".*:Exp_cond", "Exp_cond"),
    term_label = paste(moderator, term, sep = " x ")  # Combine for unique labeling
  )

# Reorder the moderator factor levels
interaction_terms_all$moderator <- factor(
  interaction_terms_all$moderator,
  levels = c("Male", "White nh", "NonCollege grad", "Rural", "Republican", "Voted Trump")
)

# Create a named vector for custom facet labels
facet_labels <- c(
  "Male" = "Male",
  "White nh" = "White Non-Hispanic",
  "NonCollege grad" = "Non-college graduate",
  "Rural" = "Rural",
  "Republican" = "Republican",
  "Voted Trump" = "Voted for Trump"
)

# Update the term_label to have only two labels: Automation and Offshoring
interaction_terms_all$term_label <- ifelse(
  grepl("Automation", interaction_terms_all$term_label), 
  "Automation", 
  "Offshoring"
)

# Plot the figure
ggplot(interaction_terms_all, aes(x = reorder(term_label, estimate), y = estimate)) +
  geom_point(size = 3, shape = 21, fill = "black", color = "black") +  
  geom_errorbar(aes(ymin = conf.low_90, ymax = conf.high_90), width = 0, size = 1.2) +  
  geom_errorbar(aes(ymin = conf.low_95, ymax = conf.high_95), width = 0, size = 0.8, linetype = "solid") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red", size = 1) +  
  labs(
    title = "",
    x = "",
    y = "Estimate of the interaction term\n(with 90% and 95% confidence intervals)"
  ) +
  coord_flip() +
  facet_wrap(~moderator, scales = "free_y", ncol = 1, labeller = labeller(moderator = facet_labels)) +  
  theme(
    axis.text.y = element_text(size = 10, hjust = 1),
    strip.text = element_text(size = 12, face = "bold"),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank()
  ) +
  theme

# To save the figure, please execute the below code:
#ggsave("Plots/FigE2_Heterogeneity_all_unconstrained_rules.pdf", dpi = 1200, width = 15, height = 15, unit = "in")

```

### Table E.8

```{r results='asis'}

# 1. The results

tabe8 = list()

tabe8[[1]] = lm_robust(data = data, Violence_needed ~ Republican*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe8[[2]] = lm_robust(data = data, Violence_needed ~ Voted_Trump*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe8[[3]] = lm_robust(data = data, Violence_needed ~ Male*Exp_cond + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe8[[4]] = lm_robust(data = data, Violence_needed ~ Rural*Exp_cond + Age + Empl_status + Education + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe8[[5]] = lm_robust(data = data, Violence_needed ~ White_nh*Exp_cond + Age + Empl_status + Education + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe8[[6]] = lm_robust(data = data, Violence_needed ~ NonCollege_grad*Exp_cond + Age + Empl_status + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

cat('<div style="font-size: 80%;">') # use htmlreg for knitting, otherwise use screenreg
htmlreg(tabe8, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Republican", "Automation", "Offshoring", "Republican x Automation", "Republican x Offshoring", "Voted Trump", "Voted Trump x Automation", "Voted Trump x Offshoring", "Male", "Male x Automation", "Male x Offshoring", "Rural", "Rural x Automation", "Rural x Offshoring", "White (non-Hispanic)", "White (non-Hispanic) x Automation",  "White (non-Hispanic) x Offshoring", "Non-college graduate", "Non-college graduate x Automation", "Non-college graduate x Offshoring"), reorder.coef = c(4, 3, 6, 5, 9, 8, 12, 11, 15, 14, 18, 17, 21, 20, 2, 7, 10, 13, 16, 19, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variable for all models: Politician who does not rule out force (0-10). The bankruptcy vignette is the reference category. The models include controls. All displayed variables are binary.", caption = "Effect heterogeneity tests (Politician who does not rule out force)")
cat('</div>')

```

### Table E.8 cont.

```{r}

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe8[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe8[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe8[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe8[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe8[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe8[[6]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Figure E.3

```{r warning=FALSE, fig.width=15, fig.height=15}

# Create function to extract interaction terms

extract_interactions_only <- function(model) {
  tidy(model, conf.int = TRUE, conf.level = 0.95) %>%
    filter(str_detect(term, ":Exp_cond")) %>%
    dplyr::rename(conf.low_95 = conf.low, conf.high_95 = conf.high) %>%
    left_join(
      tidy(model, conf.int = TRUE, conf.level = 0.90) %>%
        filter(str_detect(term, ":Exp_cond")) %>%
        dplyr::select(term, conf.low, conf.high) %>%
        dplyr::rename(conf.low_90 = conf.low, conf.high_90 = conf.high),
      by = "term"
    )
}

# Extract interaction terms from all models
interaction_terms_all <- map_dfr(tabe8, extract_interactions_only, .id = "model_id")

# Create a moderator variable to group the interaction terms
interaction_terms_all <- interaction_terms_all %>%
  mutate(
    moderator = str_extract(term, "^[^:]+") %>% str_replace("_", " "),
    term = str_replace(term, ".*:Exp_cond", "Exp_cond"),
    term_label = paste(moderator, term, sep = " x ")  # Combine for unique labeling
  )

# Reorder the moderator factor levels
interaction_terms_all$moderator <- factor(
  interaction_terms_all$moderator,
  levels = c("Male", "White nh", "NonCollege grad", "Rural", "Republican", "Voted Trump")
)

# Create a named vector for custom facet labels
facet_labels <- c(
  "Male" = "Male",
  "White nh" = "White Non-Hispanic",
  "NonCollege grad" = "Non-college graduate",
  "Rural" = "Rural",
  "Republican" = "Republican",
  "Voted Trump" = "Voted for Trump"
)

# Update the term_label to have only two labels: Automation and Offshoring
interaction_terms_all$term_label <- ifelse(
  grepl("Automation", interaction_terms_all$term_label), 
  "Automation", 
  "Offshoring"
)

# Plot the figure
ggplot(interaction_terms_all, aes(x = reorder(term_label, estimate), y = estimate)) +
  geom_point(size = 3, shape = 21, fill = "black", color = "black") +  
  geom_errorbar(aes(ymin = conf.low_90, ymax = conf.high_90), width = 0, size = 1.2) +  
  geom_errorbar(aes(ymin = conf.low_95, ymax = conf.high_95), width = 0, size = 0.8, linetype = "solid") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red", size = 1) +  
  labs(
    title = "",
    x = "",
    y = "Estimate of the interaction term\n(with 90% and 95% confidence intervals)"
  ) +
  coord_flip() +
  facet_wrap(~moderator, scales = "free_y", ncol = 1, labeller = labeller(moderator = facet_labels)) +  
  theme(
    axis.text.y = element_text(size = 10, hjust = 1),
    strip.text = element_text(size = 12, face = "bold"),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank()
  ) +
  theme

# To save the figure, please execute the below code:
#ggsave("Plots/FigE3_Heterogeneity_all_violence_needed.pdf", dpi = 1200, width = 15, height = 15, unit = "in")

```

### Table E.9

```{r results='asis'}

# 1. The results

tabe9 = list()

tabe9[[1]] = lm_robust(data = data, Local_constituents ~ Republican*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe9[[2]] = lm_robust(data = data, Local_constituents ~ Voted_Trump*Exp_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe9[[3]] = lm_robust(data = data, Local_constituents ~ Male*Exp_cond + Age + Empl_status + Education + Residence + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe9[[4]] = lm_robust(data = data, Local_constituents ~ Rural*Exp_cond + Age + Empl_status + Education + Race + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe9[[5]] = lm_robust(data = data, Local_constituents ~ White_nh*Exp_cond + Age + Empl_status + Education + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

tabe9[[6]] = lm_robust(data = data, Local_constituents ~ NonCollege_grad*Exp_cond + Age + Empl_status + Residence + Democrat + Ideology + Polint_high + Region, se_type = "stata")

cat('<div style="font-size: 80%;">') # use htmlreg for knitting, otherwise use screenreg
htmlreg(tabe9, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Republican", "Automation", "Offshoring", "Republican x Automation", "Republican x Offshoring", "Voted Trump", "Voted Trump x Automation", "Voted Trump x Offshoring", "Male", "Male x Automation", "Male x Offshoring", "Rural", "Rural x Automation", "Rural x Offshoring", "White (non-Hispanic)", "White (non-Hispanic) x Automation",  "White (non-Hispanic) x Offshoring", "Non-college graduate", "Non-college graduate x Automation", "Non-college graduate x Offshoring"), reorder.coef = c(4, 3, 6, 5, 9, 8, 12, 11, 15, 14, 18, 17, 21, 20, 2, 7, 10, 13, 16, 19, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variable for all models: Politician who accepts divisiveness (0-10). The bankruptcy vignette is the reference category. The models include controls. All displayed variables are binary.", caption = "Effect heterogeneity tests (Politician who accepts divisiveness)")
cat('</div>')

```

### Table E.9 cont.

```{r}

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe9[[1]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe9[[2]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe9[[3]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe9[[4]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe9[[5]], "Exp_condAutomation - Exp_condOffshoring = 0")
linearHypothesis(tabe9[[6]], "Exp_condAutomation - Exp_condOffshoring = 0")

```

### Figure E.4

```{r warning=FALSE, fig.width=15, fig.height=15}

# Create function to extract interaction terms

extract_interactions_only <- function(model) {
  tidy(model, conf.int = TRUE, conf.level = 0.95) %>%
    filter(str_detect(term, ":Exp_cond")) %>%
    dplyr::rename(conf.low_95 = conf.low, conf.high_95 = conf.high) %>%
    left_join(
      tidy(model, conf.int = TRUE, conf.level = 0.90) %>%
        filter(str_detect(term, ":Exp_cond")) %>%
        dplyr::select(term, conf.low, conf.high) %>%
        dplyr::rename(conf.low_90 = conf.low, conf.high_90 = conf.high),
      by = "term"
    )
}

# Extract interaction terms from all models
interaction_terms_all <- map_dfr(tabe9, extract_interactions_only, .id = "model_id")

# Create a moderator variable to group the interaction terms
interaction_terms_all <- interaction_terms_all %>%
  mutate(
    moderator = str_extract(term, "^[^:]+") %>% str_replace("_", " "),
    term = str_replace(term, ".*:Exp_cond", "Exp_cond"),
    term_label = paste(moderator, term, sep = " x ")  # Combine for unique labeling
  )

# Reorder the moderator factor levels
interaction_terms_all$moderator <- factor(
  interaction_terms_all$moderator,
  levels = c("Male", "White nh", "NonCollege grad", "Rural", "Republican", "Voted Trump")
)

# Create a named vector for custom facet labels
facet_labels <- c(
  "Male" = "Male",
  "White nh" = "White Non-Hispanic",
  "NonCollege grad" = "Non-college graduate",
  "Rural" = "Rural",
  "Republican" = "Republican",
  "Voted Trump" = "Voted for Trump"
)

# Update the term_label to have only two labels: Automation and Offshoring
interaction_terms_all$term_label <- ifelse(
  grepl("Automation", interaction_terms_all$term_label), 
  "Automation", 
  "Offshoring"
)

# Plot the figure
ggplot(interaction_terms_all, aes(x = reorder(term_label, estimate), y = estimate)) +
  geom_point(size = 3, shape = 21, fill = "black", color = "black") +  
  geom_errorbar(aes(ymin = conf.low_90, ymax = conf.high_90), width = 0, size = 1.2) +  
  geom_errorbar(aes(ymin = conf.low_95, ymax = conf.high_95), width = 0, size = 0.8, linetype = "solid") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red", size = 1) +  
  labs(
    title = "",
    x = "",
    y = "Estimate of the interaction term\n(with 90% and 95% confidence intervals)"
  ) +
  coord_flip() +
  facet_wrap(~moderator, scales = "free_y", ncol = 1, labeller = labeller(moderator = facet_labels)) +  
  theme(
    axis.text.y = element_text(size = 10, hjust = 1),
    strip.text = element_text(size = 12, face = "bold"),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank()
  ) +
  theme

# To save the figure, please execute the below code:
#ggsave("Plots/FigE4_Heterogeneity_all_local_constituents.pdf", dpi = 1200, width = 15, height = 15, unit = "in")

```

### Table E.10

```{r}

# 0. Data recode

data = mutate(data,
              Manufacturing1 = factor(Manufacturing, labels = c("Non-manufacturing", "Manufacturing")))

# 1. The results

tabe10 = list()

tabe10[[1]] = lm_robust(data = data, Prevent_layoffs ~ Manufacturing1*Automation_cond + Manufacturing1*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe10[[2]] = lm_robust(data = data, Populism ~ Manufacturing1*Automation_cond + Manufacturing1*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe10[[3]] = lm_robust(data = data, Authoritarianism ~ Manufacturing1*Automation_cond + Manufacturing1*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe10, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Manufacturing", "Automation", "Offshoring", "Manufacturing * Automation", "Manufacturing * Offshoring"), reorder.coef = c(4, 3, 6, 5, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Politicians should prevent these layoffs - model 1; Populism - model 2; Authoritarianism - model 3. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe10[[1]], "Automation_cond  - Offshoring_cond = 0")
linearHypothesis(tabe10[[2]], "Automation_cond  - Offshoring_cond = 0")
linearHypothesis(tabe10[[3]], "Automation_cond  - Offshoring_cond = 0")

```

### Figure E.5

```{r warning=FALSE, fig.width=20, fig.height=10}

# Preventing layoffs

man_int_1 = plot_slopes(tabe10[[1]], variables = "Offshoring_cond", condition = "Manufacturing1", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3)) +
  labs(x = "", y = "", title = "Marginal effects of Offshoring on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme

man_int_2 = plot_slopes(tabe10[[1]], variables = "Automation_cond", condition = "Manufacturing1", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3)) +
  labs(x = "", y = "", title = "Marginal effects of Automation on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme
  
man_int_1 + man_int_2

# To save the figure, please execute the below code:
#ggsave("Plots/FigE5_Heterogeneity_manuf_prevent.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.6

```{r warning=FALSE, fig.width=20, fig.height=10}

# Populism

man_int_3 = plot_slopes(tabe10[[2]], variables = "Offshoring_cond", condition = "Manufacturing1", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "", y = "", title = "Marginal effects of Offshoring on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme

man_int_4 = plot_slopes(tabe10[[2]], variables = "Automation_cond", condition = "Manufacturing1", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "", y = "", title = "Marginal effects of Automation on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme
  
man_int_3 + man_int_4

# To save the figure, please execute the below code:
#ggsave("Plots/FigE6_Heterogeneity_manuf_populism.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.7

```{r warning=FALSE, fig.width=20, fig.height=10}

# Authoritarianism

man_int_5 = plot_slopes(tabe10[[3]], variables = "Offshoring_cond", condition = "Manufacturing1", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-0.4, 1, 0.2), limits=c(-0.4, 1)) +
  labs(x = "", y = "", title = "Marginal effects of Offshoring on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme

man_int_6 = plot_slopes(tabe10[[3]], variables = "Automation_cond", condition = "Manufacturing1", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-0.4, 1, 0.2), limits=c(-0.4, 1)) +
  labs(x = "", y = "", title = "Marginal effects of Automation on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme
  
man_int_5 + man_int_6

# To save the figure, please execute the below code:
#ggsave("Plots/FigE7_Heterogeneity_manuf_auth.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Table E.11

```{r}

# 1. The results
  
tabe11 = list()
  
tabe11[[1]] = lm_robust(data = data, Prevent_layoffs ~ Offshoring_Goos*Automation_cond + Offshoring_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")
  
tabe11[[2]] = lm_robust(data = data, Populism ~ Offshoring_Goos*Automation_cond + Offshoring_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")
  
tabe11[[3]] = lm_robust(data = data, Authoritarianism ~ Offshoring_Goos*Automation_cond + Offshoring_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")
  
screenreg(tabe11, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Vulnerability to offshoring", "Automation", "Offshoring", "Vulnerability to offshoring * Automation", "Vulnerability to offshoring * Offshoring"), reorder.coef = c(4, 3, 6, 5, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Politicians should prevent these layoffs - model 1; Populism - model 2; Authoritarianism - model 3. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe11[[1]], "Automation_cond - Offshoring_cond = 0")
linearHypothesis(tabe11[[2]], "Automation_cond - Offshoring_cond = 0")
linearHypothesis(tabe11[[3]], "Automation_cond - Offshoring_cond = 0")

```

### Figure E.8

```{r warning=FALSE, fig.width=20, fig.height=10}

# Preventing layoffs

offgoos_int_1 = plot_slopes(tabe11[[1]], variables = "Offshoring_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme

offgoos_int_2 = plot_slopes(tabe11[[1]], variables = "Automation_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme
  
offgoos_int_1 + offgoos_int_2

# To save the figure, please execute the below code:
#ggsave("Plots/FigE8_Heterogeneity_offgoos_prevent.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.9

```{r warning=FALSE, fig.width=20, fig.height=10}

# Populism

offgoos_int_3 = plot_slopes(tabe11[[2]], variables = "Offshoring_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme

offgoos_int_4 = plot_slopes(tabe11[[2]], variables = "Automation_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme
  
offgoos_int_3 + offgoos_int_4

# To save the figure, please execute the below code:
#ggsave("Plots/FigE9_Heterogeneity_offgoos_populism.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.10

```{r warning=FALSE, fig.width=20, fig.height=10}

# Authoritarianism

offgoos_int_5 = plot_slopes(tabe11[[3]], variables = "Offshoring_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-1, 1.2, 0.2), limits=c(-1, 1.2), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme

offgoos_int_6 = plot_slopes(tabe11[[3]], variables = "Automation_cond", condition = "Offshoring_Goos", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-1, 1.2, 0.2), limits=c(-1, 1.2), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to offshoring (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme
  
offgoos_int_5 + offgoos_int_6

# To save the figure, please execute the below code:
#ggsave("Plots/FigE10_Heterogeneity_offgoos_auth.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Table E.12

```{r}

# 1. The results

tabe12 = list()

tabe12[[1]] = lm_robust(data = data, Prevent_layoffs ~ RTI_Goos*Automation_cond + RTI_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe12[[2]] = lm_robust(data = data, Populism ~ RTI_Goos*Automation_cond + RTI_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

tabe12[[3]] = lm_robust(data = data, Authoritarianism ~ RTI_Goos*Automation_cond + RTI_Goos*Offshoring_cond + Sex + Age + Empl_status + Education + Residence + Race + Democrat + Voted_Biden + Ideology + Polint_high + Region, se_type = "stata")

screenreg(tabe12, include.ci = FALSE, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Sex|Age|Empl_status|Education|Residence|Race|Democrat|Voted_Biden|Ideology|Polint_high|Region", custom.coef.names = c("Constant", "Vulnerability to automation", "Automation", "Offshoring", "Vulnerability to automation * Automation", "Vulnerability to automation * Offshoring"), reorder.coef = c(4, 3, 6, 5, 2, 1), custom.note = "Note: %stars. OLS estimations with robust standard errors in parentheses. Dependent variables (0 - 10): Politicians should prevent these layoffs - model 1; Populism - model 2; Authoritarianism - model 3. The bankruptcy vignette is the reference category.")

# 2. We further test whether beta_Offshoring and beta_Automation are equal (the p-values indicate whether we can reject the null hypothesis of equality).

linearHypothesis(tabe12[[1]], "Automation_cond - Offshoring_cond = 0")
linearHypothesis(tabe12[[2]], "Automation_cond - Offshoring_cond = 0")
linearHypothesis(tabe12[[3]], "Automation_cond - Offshoring_cond = 0")

```

### Figure E.11

```{r warning=FALSE, fig.width=20, fig.height=10}

# Preventing layoffs

rtigoos_int_1 = plot_slopes(tabe12[[1]], variables = "Offshoring_cond", condition = "RTI_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme

rtigoos_int_2 = plot_slopes(tabe12[[1]], variables = "Automation_cond", condition = "RTI_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(0, 3, 0.5), limits=c(0, 3), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nPreventing layoffs", subtitle = "(with 90% confidence intervals)") +
  theme
  
rtigoos_int_1 + rtigoos_int_2

# To save the figure, please execute the below code:
#ggsave("Plots/FigE11_Heterogeneity_rtigoos_prevent.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.12

```{r warning=FALSE, fig.width=20, fig.height=10}

# Populism

rtigoos_int_3 = plot_slopes(tabe12[[2]], variables = "Offshoring_cond", condition = "RTI_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme

rtigoos_int_4 = plot_slopes(tabe12[[2]], variables = "Automation_cond", condition = "RTI_Goos", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-1, 0.6, 0.2), limits=c(-1, 0.6), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nPopulism", subtitle = "(with 90% confidence intervals)") +
  theme
  
rtigoos_int_3 + rtigoos_int_4

# To save the figure, please execute the below code:
#ggsave("Plots/FigE12_Heterogeneity_rtigoos_populism.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

### Figure E.13

```{r warning=FALSE, fig.width=20, fig.height=10}

# Authoritarianism

rtigoos_int_5 = plot_slopes(tabe12[[3]], variables = "Offshoring_cond", condition = "RTI_Goos", conf.level = 0.9) +
   scale_y_continuous(breaks = seq(-1, 1.2, 0.2), limits=c(-1, 1.2), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Offshoring on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme

rtigoos_int_6 = plot_slopes(tabe12[[3]], variables = "Automation_cond", condition = "RTI_Goos", conf.level = 0.9) +
  scale_y_continuous(breaks = seq(-1, 1.2, 0.2), limits=c(-1, 1.2), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Vulnerability to automation (Goos et. al (2014))", y = "", title = "Marginal effects of Automation on\nAuthoritarianism", subtitle = "(with 90% confidence intervals)") +
  theme
  
rtigoos_int_5 + rtigoos_int_6

# To save the figure, please execute the below code:
#ggsave("Plots/FigE13_Heterogeneity_rtigoos_auth.pdf", dpi = 1200, width = 20, height = 10, unit = "in")

```

# End.